// component/date-slider/index.js
Component({
  properties: {
    // 允许外部传入的日期数据
    dateList: {
      type: Array,
      value: [],
      observer: function(newVal) {
        // 初始化激活状态
        const dates = newVal.map((item, index) => {
          return {
            ...item,
            active: index === 0
          }
        })
        this.setData({ dates })
      }
    }
  },

  data: {
    dates: []
  },

  methods: {
    getWeekDay(day) {
      const weekDays = ['日', '一', '二', '三', '四', '五', '六'];
      return `周${weekDays[day]}`;
    },

    handleItemTap(e) {
      const index = e.currentTarget.dataset.index;
      const newDates = this.data.dates.map((item, i) => ({
        ...item,
        active: i === index
      }));
      
      this.setData({ dates: newDates });
      this.triggerEvent('datechange', { 
        index: index,
        date: newDates[index]
      });
    }
  }
});